package com.parkinginfo.manager;

/*
 * Author: Deepika Gohil
 */

import com.parkinginfo.adapters.PlacesListAdapter;
import com.parkinginfo.dbhelper.Place;
import com.parkinginfo.manager.R;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;

public class MainScreenActivity extends ListActivity {

	private Button aroundMeButton;
	private ImageButton addLocButton;
	private PlacesListAdapter adapter;
	private ParkingManagerApplication app;
	//private Button removeButton;

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        setUpViews();
        app = (ParkingManagerApplication)getApplication();
        adapter = new PlacesListAdapter(this, app.getPlaces());
        setListAdapter(adapter);
    }
	
	@Override
	protected void onResume() {
		super.onResume();
		adapter.forceReload();
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) 
	{
		super.onListItemClick(l, v, position, id);
		Place t = adapter.getItem(position);
		Double lat = t.getLattitude();
		Double lon = t.getLongitude();
		
		Intent intent = new Intent(MainScreenActivity.this, GoogleParkingActivity.class);
		intent.putExtra("lat", lat);
		intent.putExtra("lon", lon);
		startActivity(intent);
	}
	
	private void setUpViews() 
	{
		aroundMeButton = (Button)findViewById(R.id.aroundme_button);
		addLocButton = (ImageButton)findViewById(R.id.favorite);
		
		aroundMeButton.setOnClickListener(new View.OnClickListener() {
		      public void onClick(View v) {
		    	  Intent intent = new Intent(MainScreenActivity.this, GoogleParkingActivity.class);
				  startActivity(intent);
		        }
		      });
		addLocButton.setOnClickListener(new View.OnClickListener() {
		      public void onClick(View v) {
		    	  Intent intent = new Intent(MainScreenActivity.this, SimpleMapsActivity.class);
				  startActivity(intent);
		        }
		      });

	}

}